package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.common.converter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author: niechanggang
 * @date:2021/8/6 16:03
 * @description:
 */
public class CustomDelegate  implements JavaDelegate {

    private Logger logger  = LoggerFactory.getLogger(this.getClass());

    @Override
    public void execute(DelegateExecution execution) {
        String executionId = execution.getId();
        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
        ExecutionEntity executionEntity = executionEntityManager.findById(executionId);
        Map<String, Object> variables = executionEntity.getVariables();
        logger.info(JSON.toJSONString(variables, SerializerFeature.PrettyFormat));
    }
}
